<template>
  <div>
    <UseBreadcrumb>
      <el-breadcrumb-item v-for="item of ['订单管理', '订单列表']" :key="item">
        {{ item }}
      </el-breadcrumb-item>
    </UseBreadcrumb>
    <el-card>
      <el-row>
        <el-col :span="8">
          <el-input placeholder="请输入内容" class="input-with-select">
            <el-button slot="append" icon="el-icon-search"></el-button>
          </el-input>
        </el-col>
      </el-row>
      <!-- 订单表格区域 -->
      <el-table :data="ordersList" border stripe="" style="width: 100%">
        <el-table-column type="index" label="#"> </el-table-column>
        <el-table-column prop="order_number" label="订单编号">
        </el-table-column>
        <el-table-column prop="order_price" label="订单价格"> </el-table-column>
        <el-table-column prop="pay_status" label="是否付款">
          <template slot-scope="scope">
            <el-tag v-if="scope.row.pay_status === '0'" type="danger"
              >未付款</el-tag
            >
            <el-tag v-else>已付款</el-tag>
          </template>
        </el-table-column>
        <el-table-column prop="is_send" label="是否发货"> </el-table-column>
        <el-table-column prop="create_time" label="下单时间">
          <template slot-scope="scope">
            {{ scope.row.create_time | dateFormat }}
          </template>
        </el-table-column>
        <el-table-column label="操作">
          <template slot-scope="scope">
            <el-button type="primary" icon="el-icon-edit" size="mini"
              >地址</el-button
            >
            <el-button
              type="success"
              icon="el-icon-location-outline"
              size="mini"
              @click="showLogistics"
              >信息</el-button
            >
          </template>
        </el-table-column>
      </el-table>
      <!-- 分页区域 -->
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="queryInfo.pagenum"
        :page-sizes="[10, 20, 30, 40]"
        :page-size="queryInfo.pagesize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total"
      >
      </el-pagination>
      <!-- 物流信息弹框 -->
      <el-dialog
        title="物流信息"
        :visible.sync="logisticsDialogVisible"
        width="50%"
      >
        <el-timeline>
          <el-timeline-item
            v-for="(activity, index) in activities"
            :key="index"
            :timestamp="activity.timestamp"
          >
            {{ activity.content }}
          </el-timeline-item>
        </el-timeline>
        <span slot="footer" class="dialog-footer">
          <el-button @click="logisticsDialogVisible = false">取 消</el-button>
          <el-button type="primary" @click="logisticsDialogVisible = false"
            >确 定</el-button
          >
        </span>
      </el-dialog>
    </el-card>
  </div>
</template>

<script>
import UseBreadcrumb from '@/common_components/UseBreadcrumb'
export default {
  data() {
    return {
      //订单请求信息
      queryInfo: {
        query: '',
        pagenum: 1,
        pagesize: 10,
      },
      //订单数据列表
      ordersList: [],
      //页面展示订单总条数
      total: 0,
      //物流信息弹框展示与隐藏
      logisticsDialogVisible: false,
      //物流信息
      activities: [
        {
          content: '活动按期开始',
          timestamp: '2018-04-15',
        },
        {
          content: '通过审核',
          timestamp: '2018-04-13',
        },
        {
          content: '创建成功',
          timestamp: '2018-04-11',
        },
      ],
    }
  },
  created() {
    this.getOrdersList()
  },
  methods: {
    //获取订单数据列表
    async getOrdersList() {
      let {
        data: { data: res, meta },
      } = await this.$api.getOrdersData(this.queryInfo)
      if (meta.status !== 200) return this.$message.error('请求失败')
      this.ordersList = res.goods
      this.total = res.total
      console.log(res.goods)
    },
    //监听当前页面条数变化
    handleSizeChange(newSize) {
      this.queryInfo.pagesize = newSize
      this.getOrdersList()
    },
    //监听当前页面页码变化
    handleCurrentChange(newNum) {
      this.queryInfo.pagenum = newNum
      this.getOrdersList()
    },
    //获取物流信息数据
    async getLogisticsList() {
      let res = await this.$api.getLogisticsData()
      console.log(res)
    },
    //查看物流信息
    showLogistics() {
      this.logisticsDialogVisible = true
      //this.getLogisticsList()
    },
  },
  components: { UseBreadcrumb },
}
</script>

<style lang="less" scoped>
.el-card {
  height: 100%;
}
.el-table {
  margin-top: 10px;
}
.el-pagination {
  margin-top: 10px;
}
</style>